
#ifndef RTCHANNELHTTPSERVER_H
#define RTCHANNELHTTPSERVER_H

#include "RtHttpInterface.h"
#include "RtChannelHttpBase.h"
#include "RtHttpHeadParser.h"

class /*RT_API_EXPORT*/ CRtChannelHttpServer 
	: public IRtChannelHttpServer  
	, public CRtChannelHttpBase
	, public CRtReferenceControlSingleThreadTimerDelete
{
public:
	CRtChannelHttpServer(IRtTransport *aTrpt);
	virtual ~CRtChannelHttpServer();

	// interface IRtReferenceControl
	virtual DWORD AddReference();
	virtual DWORD ReleaseReference();

	// interface IRtTransport
	virtual RtResult OpenWithSink(IRtTransportSink *aSink);
	virtual IRtTransportSink* GetSink();
	virtual RtResult SendData(
		CRtMessageBlock& inData,
		BOOL inSendImmediately = TRUE,
		BOOL inDestroyData = FALSE,
		DataPriority inPriority = DP_MEDIUM, 
		BOOL inNeedAck = TRUE);
	virtual RtResult SetOption(DWORD aCommand, LPVOID aArg);
	virtual RtResult GetOption(DWORD aCommand, LPVOID aArg);
	virtual RtResult Disconnect(RtResult aReason);

	// interface IRtChannelHttpServer
	virtual RtResult SetOrAddResponseHeader(
		const CRtString &aHeader, 
		const CRtString &aValue);

	virtual RtResult SetResponseStatus(DWORD aStatus, const CRtString &aText);

	virtual RtResult GetRequestMethod(CRtString &aMethod);

	virtual RtResult GetRequestHeader(
		const CRtString &aHeader, 
		CRtString &aValue);

	virtual RtResult GetRequestPath(CRtString &aPath);

	virtual RtResult GetUploadFileInfo(
		CRtMessageBlock& inData, 
		const CRtString& inInputTagName, 
		CRtString& outFileName, 
		CRtString& outFileContent);

	virtual IRtTransport* GetTcpTransport();

	virtual RtResult PrepareResponse(CRtMessageBlock& data);
	virtual RtResult Response();

protected:
	virtual RtResult ParserHttpProtocol_t(CRtMessageBlock &aData);
	virtual RtResult Close_t(RtResult aReason);

private:
	CRtAutoPtr<CRtHttpUrl> m_pURL;
	CRtHttpParserT<CRtHttpRequestHead, CRtChannelHttpServer> m_ParserRequest;
	CRtMessageBlock*	m_response_data;
	BOOL				m_bOpenWith;
};

#endif // !RTCHANNELHTTPSERVER_H
